﻿<Window x:Class="EntertainmentManager.Views.frmEntertainmentManager"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:convlocal="clr-namespace:EntertainmentManager.Converters"
        xmlns:conv="clr-namespace:CommonUtilities.Converters;assembly=CommonUtilities"
        xmlns:vm="clr-namespace:EntertainmentManager.ViewModels"
        xmlns:local="clr-namespace:EntertainmentManager.ViewModels"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:da="clr-namespace:DirectoryAnalyzer.Controls"
        Title="{Binding AppTitle}" Icon="/EntertainmentManager;component/EntMgr.ico"
        MinHeight="600" MinWidth="800" 
        WindowStartupLocation="CenterScreen"  WindowState="Maximized">
    <Window.Resources>
        <AlternationConverter x:Key="AlternationConverter"/>
        <convlocal:ImdbUrlConverter x:Key="ImdbUrlConverter" />
        <conv:NumberPaddingConverter x:Key="NumberPaddingConverter" />
        <conv:InvalidDateConverter x:Key="InvalidDateConverter" />
        <conv:VisibilityConverter x:Key="VisibilityConverter" />
        <conv:UIOffsetConverter x:Key="UIOffsetConverter" />

        <DataTemplate x:Key="coltempSort">
            <Label Content="{Binding Sort}" />
        </DataTemplate>
        <DataTemplate x:Key="coltempSeriesTitle">
            <Label Content="{Binding SeriesTitle}" />
        </DataTemplate>
        <DataTemplate x:Key="coltempSeasonIndex">
            <Label Content="{Binding SeasonIndex, Converter={StaticResource NumberPaddingConverter}, ConverterParameter=2}" />
        </DataTemplate>
        <DataTemplate x:Key="coltempEpisodeIndex">
            <Label Content="{Binding EpisodeIndex, Converter={StaticResource NumberPaddingConverter}, ConverterParameter=2}" />
        </DataTemplate>
        <DataTemplate x:Key="coltempEpisodeTitle">
            <Label Content="{Binding EpisodeTitle}" />
        </DataTemplate>
        <DataTemplate x:Key="coltempFileName">
            <Label Content="{Binding FileName}" />
        </DataTemplate>
        <DataTemplate x:Key="coltempFileExtn">
            <Label Content="{Binding FileExtn}" />
        </DataTemplate>
        <DataTemplate x:Key="coltempImdbUrl">
            <Label Name="btnImdbUrl" BorderBrush="Transparent" BorderThickness="0">
                <Hyperlink Name="lnkImdbUrl" CommandParameter="{Binding ElementName=txtImdbUrl, Path=Text}"
                           Command="{Binding DataContext.OpenLinkCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}">
                    <Hyperlink.ToolTip>
                        <TextBlock Text="Click to follow link.." />
                    </Hyperlink.ToolTip>
                    <TextBlock Name="txtImdbUrl" Text="{Binding Converter={StaticResource ImdbUrlConverter}}" />
                </Hyperlink>
            </Label>
        </DataTemplate>
        <DataTemplate x:Key="coltempFullPath">
            <Label Name="btnFullPath" BorderBrush="Transparent" BorderThickness="0">
                <Hyperlink Name="lnkFullPath" CommandParameter="{Binding ElementName=txtFullPath, Path=Text}"
                           Command="{Binding DataContext.OpenLinkCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}">
                    <Hyperlink.ToolTip>
                        <TextBlock Text="Click to open path/file.." />
                    </Hyperlink.ToolTip>
                    <TextBlock Name="txtFullPath" Text="{Binding FullPath}" />
                </Hyperlink>
            </Label>
        </DataTemplate>
        <DataTemplate x:Key="coltempActuallPath">
            <Label Name="btnActuallPath" BorderBrush="Transparent" BorderThickness="0">
                <Hyperlink Name="lnkActuallPath" CommandParameter="{Binding ElementName=txtActuallPath, Path=Text}"
                           Command="{Binding DataContext.OpenLinkCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}">
                    <Hyperlink.ToolTip>
                        <TextBlock Text="Click to open path/file.." />
                    </Hyperlink.ToolTip>
                    <TextBlock Name="txtActuallPath" Text="{Binding ActuallPath}" />
                </Hyperlink>
            </Label>
        </DataTemplate>
        <DataTemplate x:Key="coltempOrgAirDate">
            <Label Content="{Binding OriginalAirDate, Converter={StaticResource InvalidDateConverter}, ConverterParameter='dd MMM yyyy'}" />
        </DataTemplate>
        <DataTemplate x:Key="coltempDescription">
            <Label Name="lblDescription">
                <Label.ToolTip>
                    <TextBlock Text="{Binding Description}" Width="250" TextWrapping="Wrap" />
                </Label.ToolTip>
                <TextBlock Name="txtbDescription" Text="{Binding Description}" Width="325" VerticalAlignment="Stretch" />
                <!--TextWrapping="Wrap"-->
            </Label>
        </DataTemplate>
        <DataTemplate x:Key="coltempFileExists">
            <Label Name="lblFileExists">
                <CheckBox Name="chkFileExists" IsChecked="{Binding FileExists, Mode=OneWay}" IsEnabled="False" Content="" HorizontalAlignment="Center" />
            </Label>
        </DataTemplate>
    </Window.Resources>

    <Grid Name="MainLayout" Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <Grid Name="stkEntertainmentType" Grid.ColumnSpan="2" HorizontalAlignment="Left">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Label Name="lblEntertainmentType" Grid.Column="0" Content="Type:" />
            <ComboBox Name="cmbEntertainmentType" Grid.Column="1" Margin="2,1" Width="200">
            </ComboBox>
        </Grid>
        <StackPanel Name="stkGroupMode" Grid.Column="1" Grid.ColumnSpan="2" Margin="5,0" HorizontalAlignment="Right" Orientation="Horizontal">
            <Label Name="lblGroupBy" Content="Group by:" />
            <RadioButton Name="radEpisode" Margin="2.5,0" Content="Episodes" Command="{Binding DisplayGroupCommand}" CommandParameter="{x:Static local:eDisplayGroup.Episode}" />
            <RadioButton Name="radSeason" Margin="2.5,0" Content="Seasons" Command="{Binding DisplayGroupCommand}" CommandParameter="{x:Static local:eDisplayGroup.Season}" />
            <RadioButton Name="radSeries" Margin="2.5,0" Content="Series" Command="{Binding DisplayGroupCommand}" CommandParameter="{x:Static local:eDisplayGroup.Series}" />
            <RadioButton Name="radHierarchical" Margin="2.5,0" Content="Hierarchical" Command="{Binding DisplayGroupCommand}" CommandParameter="{x:Static local:eDisplayGroup.Hierarchical}" />
            <RadioButton Name="radSummary" Margin="2.5,0" Content="Summary" Command="{Binding DisplayGroupCommand}" CommandParameter="{x:Static local:eDisplayGroup.Summary}" />
        </StackPanel>

        <Grid Name="grdFilter" Grid.Row="1" Grid.ColumnSpan="3">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <StackPanel Name="stkFilters" Orientation="Horizontal">
                <Label Name="lblFilterType" Content="Select filter: " />
                <ComboBox Name="cmbSeries" Width="100" Margin="2,1" 
                          ItemsSource="{Binding AllSeriesFilter}" SelectedItem="{Binding SelectedSeries, Mode=TwoWay}" />
                <ComboBox Name="cmbFilterType" Width="100" Margin="2,1" IsEnabled="{Binding IsFilterEnabled}"
                          SelectedValuePath="Key" DisplayMemberPath="Value"
                          ItemsSource="{Binding AllFilters}" SelectedValue="{Binding SelectedFilter, Mode=TwoWay}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="SourceUpdated">
                            <i:InvokeCommandAction Command="{Binding FiltersUpdatedCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>

                </ComboBox>
                <Label Name="lblFilterAll">
                    <Hyperlink Name="lnkFilterAll" IsEnabled="{Binding IsFilterEnabled}" Command="{Binding FilterDataCommand}" 
                               CommandParameter="{Binding ElementName=txtFilterAll, Path=Text}">
                        <TextBlock Name="txtFilterAll" Text="{Binding DefaultAll, FallbackValue=All}" />
                    </Hyperlink>
                </Label>
            </StackPanel>
            <ScrollViewer Grid.Column="1" Margin="2,1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden" 
                          Style="{StaticResource SidePageScrollStyle}" IsEnabled="{Binding IsFilterEnabled}">
                <ItemsControl ItemsSource="{Binding AllFilterValues}" Margin="0.5">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Label>
                                <Hyperlink Name="lnkFilter" CommandParameter="{Binding ElementName=txtFilter, Path=Text}" 
                                           Command="{Binding DataContext.FilterDataCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}" >
                                    <TextBlock Name="txtFilter" Text="{Binding }" />
                                </Hyperlink>
                            </Label>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>
        </Grid>

        <DataGrid Name="dgrdEpisodes" Grid.Row="2" Grid.ColumnSpan="3" AreRowDetailsFrozen="True" 
                  AutoGenerateColumns="False" FrozenColumnCount="5" ItemsSource="{Binding AllEpisodeInfo}"
                  Visibility="{Binding ElementName=radHierarchical, Path=IsChecked, Converter={StaticResource VisibilityConverter}, ConverterParameter=-}">
            <!--<DataGrid.CellStyle>
                <Style TargetType="DataGridCell">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Label HorizontalAlignment="Stretch" VerticalAlignment="Center" 
                                       HorizontalContentAlignment="Left" VerticalContentAlignment="Center">
                                    <ContentPresenter VerticalAlignment="Center" />
                                </Label>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </DataGrid.CellStyle>-->
            <DataGrid.Columns>
                <DataGridTemplateColumn x:Name="dgcolSort" Header="#" 
                                        CellTemplate="{StaticResource coltempSort}" />
                <DataGridTemplateColumn x:Name="dgcolSeriesTitle" Header="Series" 
                                        CellTemplate="{StaticResource coltempSeriesTitle}" />
                <DataGridTemplateColumn x:Name="dgcolSeasonIndex" Header="S#" HeaderStringFormat="##" 
                                        CellTemplate="{StaticResource coltempSeasonIndex}" />
                <DataGridTemplateColumn x:Name="dgcolEpisodeIndex" Header="E#" HeaderStringFormat="##" 
                                        CellTemplate="{StaticResource coltempEpisodeIndex}" />
                <DataGridTemplateColumn x:Name="dgcolEpisodeTitle" Header="Title"
                                        CellTemplate="{StaticResource coltempEpisodeTitle}" />
                <DataGridTemplateColumn x:Name="dgcolFileName" Header="File Name"
                                        CellTemplate="{StaticResource coltempFileName}" />
                <DataGridTemplateColumn x:Name="dgcolFileExtn" Header="Extn."
                                        CellTemplate="{StaticResource coltempFileExtn}" />
                <!--<DataGridHyperlinkColumn Header="URL" Binding="{Binding Converter={StaticResource ImdbUrlConverter}}" />-->
                <DataGridTemplateColumn x:Name="colImdbUrl" Header="URL" 
                                        CellTemplate="{StaticResource coltempImdbUrl}" />
                <DataGridTemplateColumn x:Name="colOrgAirDate" Header="Org. air date" 
                                        CellTemplate="{StaticResource coltempOrgAirDate}" />
                <DataGridTemplateColumn x:Name="colDescription" Header="Description" 
                                        CellTemplate="{StaticResource coltempDescription}" />
                <DataGridTemplateColumn x:Name="colFileExists" Header="Exists?" 
                                        CellTemplate="{StaticResource coltempFileExists}" />
            </DataGrid.Columns>
        </DataGrid>

        <ScrollViewer Name="scrlUniversal" Grid.Row="3" Grid.ColumnSpan="3" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible"
                      Visibility="{Binding ElementName=radHierarchical, Path=IsChecked, Converter={StaticResource VisibilityConverter}, ConverterParameter=-}">
            <Grid>
                <DataGrid Name="dgrdUniversal" 
                          AlternationCount="1" AlternatingRowBackground="#FFE0D7EA" AutoGeneratingColumn="dgrdUniversal_AutoGeneratingColumn"
                          AutoGenerateColumns="True" FrozenColumnCount="{Binding FrozenColumnCount}" ItemsSource="{Binding UniversalDataSource}" AutoGeneratedColumns="dgrdUniversal_AutoGeneratedColumns" />
            </Grid>
        </ScrollViewer>

        <Grid Grid.Row="2" Grid.RowSpan="2" Grid.ColumnSpan="3"
              Visibility="{Binding ElementName=radHierarchical, Path=IsChecked, Converter={StaticResource VisibilityConverter}}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <ToggleButton Name="tgl" Content="Toggle Hiearchy / Files" IsChecked="True" />

            <ScrollViewer Name="scrlHierarchicalDisplay" Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible"
                          Visibility="{Binding ElementName=radHierarchical, Path=IsChecked, Converter={StaticResource VisibilityConverter}}">
                <StackPanel Name="stkHierSeries" Orientation="Vertical" 
                            Visibility="{Binding ElementName=tgl, Path=IsChecked, Converter={StaticResource VisibilityConverter}}">
                    <CheckBox Content="Expand all series..">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Checked">
                                <i:InvokeCommandAction Command="{Binding ToggleAllSeriesStateCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}" />
                            </i:EventTrigger>
                            <i:EventTrigger EventName="Unchecked">
                                <i:InvokeCommandAction Command="{Binding ToggleAllSeriesStateCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </CheckBox>
                    <CheckBox Content="Expand all seasons..">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Checked">
                                <i:InvokeCommandAction Command="{Binding ToggleAllSeasonStateCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=IsChecked}" />
                            </i:EventTrigger>
                            <i:EventTrigger EventName="Unchecked">
                                <i:InvokeCommandAction Command="{Binding ToggleAllSeasonStateCommand}" CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=IsChecked}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </CheckBox>
                    <TextBlock Background="Yellow">
                        <TextBlock.Text>
                            <MultiBinding StringFormat="scrl_width {0}; Series_width {1}; Season_width {2}; Eps_width {3}; Wrap_width {4}">
                                <Binding ElementName="scrlHierarchicalDisplay" Path="ActualWidth" />
                                <Binding ElementName="itmctrlHierSeries" Path="ActualWidth" />
                                <Binding ElementName="itmctrlHierSeasons" Path="ActualWidth" />
                                <Binding ElementName="itmctrlHierEpisodes" Path="ActualWidth" />
                                <Binding ElementName="wrpPanelTemplate" Path="ActualWidth" />
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>

                    <ItemsControl Name="itmctrlHierSeries" ItemsSource="{Binding AllSeriesInfo}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Expander Background="Red" Margin="5,2" HorizontalAlignment="Stretch" Header="{Binding SeriesTitle}" IsExpanded="{Binding IsExpanded}">
                                    <ItemsControl Name="itmctrlHierSeasons" ItemsSource="{Binding Seasons}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <Expander Background="Green" Margin="20,2" HorizontalAlignment="Stretch" Header="{Binding SeasonNameLong}" IsExpanded="{Binding IsExpanded}">
                                                    <ItemsControl Name="itmctrlHierEpisodes" Margin="30,2" ItemsSource="{Binding Episodes}">
                                                        <ItemsControl.ItemsPanel>
                                                            <ItemsPanelTemplate>
                                                                <WrapPanel Name="wrpPanelTemplate" Orientation="Horizontal" VerticalAlignment="Stretch" 
                                                                           Width="{Binding ElementName=itmctrlHierEpisodes, Path=ActualWidth, Converter={StaticResource UIOffsetConverter}, ConverterParameter=100}"/>
                                                            </ItemsPanelTemplate>
                                                        </ItemsControl.ItemsPanel>
                                                        <ItemsControl.ItemTemplate>
                                                            <DataTemplate>
                                                                <Border Background="Blue" Margin="2.5" BorderBrush="DarkGray" BorderThickness="1" CornerRadius="2">
                                                                    <Grid Margin="1" Width="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=ActualHeight}" IsEnabled="{Binding FileExists}" >
                                                                        <Grid.ToolTip>
                                                                            <TextBlock Width="200" TextWrapping="Wrap">
                                                                                <TextBlock.Text>
                                                                                    <Binding Path="FileName" />
                                                                                    <!--<MultiBinding StringFormat="Title: {0}&#x0a;Series: {1}&#x0a;URL: {2}&#x0a;Org. Air Date: {3}&#x0a;Full path: {4}">
                                                                                    <!- -<MultiBinding StringFormat="s{0}e{1} {2}">
                                                                                        <Binding Path="SeasonIndex" StringFormat='\{D2\}' /> 
                                                                                        <Binding Path="EpisodeIndex" StringFormat="D2" />--> <!-- RKD Use StringFormat to pad - ->
                                                                                        <Binding Path="FileName" />
                                                                                        <Binding Path="SeriesTitle" />
                                                                                        <Binding Path="ImdbUrl" />
                                                                                        <Binding Path="OriginalAirDate" />
                                                                                        <Binding Path="FullPath" />
                                                                                    </MultiBinding>-->
                                                                                </TextBlock.Text>
                                                                            </TextBlock>
                                                                        </Grid.ToolTip>
                                                                        <Grid.Background>
                                                                            <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                                                                <GradientStop Color="LightGray" Offset="0" />
                                                                                <GradientStop Color="Gray" Offset="0.5" />
                                                                                <GradientStop Color="DarkGray" Offset="1" />
                                                                            </LinearGradientBrush>
                                                                        </Grid.Background>

                                                                        <Grid.RowDefinitions>
                                                                            <RowDefinition />
                                                                            <RowDefinition />
                                                                        </Grid.RowDefinitions>
                                                                        <Grid.ColumnDefinitions>
                                                                            <ColumnDefinition />
                                                                            <ColumnDefinition />
                                                                        </Grid.ColumnDefinitions>

                                                                        <TextBlock Margin="2" HorizontalAlignment="Left" VerticalAlignment="Top" TextAlignment="Center" Text="{Binding SeasonIndex}" />
                                                                        <TextBlock Grid.Row="1" Grid.Column="1" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Bottom" TextAlignment="Center" Text="{Binding EpisodeIndex}" />
                                                                    </Grid>
                                                                </Border>
                                                            </DataTemplate>
                                                        </ItemsControl.ItemTemplate>
                                                    </ItemsControl>
                                                </Expander>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </Expander>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </StackPanel>
            </ScrollViewer>

            <da:FileAnalyzer x:Name="faFiles" Grid.Row="1" Visibility="{Binding ElementName=tgl, Path=IsChecked, Converter={StaticResource VisibilityConverter}, ConverterParameter=-}" />
        </Grid>

        <StackPanel Grid.Row="4" Grid.ColumnSpan="5" Margin="5,2">
            <Border BorderBrush="DarkGray" CornerRadius="2" />
            <Grid Name="grdStatus">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <TextBlock Name="txtbAppTitle" Grid.Row="1" Grid.Column="0" Margin="2.5" 
                           Text="{Binding AppTitle}" TextBlock.ToolTip="{Binding AppTitle}" Foreground="Gray" />
                <Ellipse Grid.Row="1" Grid.Column="1" Margin="0,2.5" Fill="Gray" Width="2" />
                <TextBlock Name="txtbStats" Grid.Row="1" Grid.Column="2" Margin="2.5" Text="{Binding LoadStatistics}" 
                           TextBlock.ToolTip="{Binding LoadStatistics, StringFormat='Stats: {0}'}" Foreground="Gray" />
                <Ellipse Grid.Row="1" Grid.Column="3" Margin="0,2.5" Fill="Gray" Width="2" />

                <Grid Grid.Row="1" Grid.Column="4" Margin="2.5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <ToggleButton Name="tglStatusDisplayMode" IsChecked="False" 
                                  VerticalContentAlignment="Center"
                                  Height="{Binding ElementName=txtbStatus, Path=ActualHeight}"
                                  Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}">
                        <ToggleButton.Style>
                            <Style TargetType="ToggleButton">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=tglStatusDisplayMode, Path=IsChecked, UpdateSourceTrigger=PropertyChanged}" Value="True">
                                        <Setter Property="Content">
                                            <Setter.Value>
                                                <TextBlock Text="-">
                                                    <TextBlock.ToolTip>
                                                        Collapse
                                                    </TextBlock.ToolTip>
                                                </TextBlock>
                                            </Setter.Value>
                                        </Setter>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding ElementName=tglStatusDisplayMode, Path=IsChecked, UpdateSourceTrigger=PropertyChanged}" Value="False">
                                        <Setter Property="Content">
                                            <Setter.Value>
                                                <TextBlock Text="+">
                                                    <TextBlock.ToolTip>
                                                        Expand
                                                    </TextBlock.ToolTip>
                                                </TextBlock>
                                            </Setter.Value>
                                        </Setter>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </ToggleButton.Style>
                    </ToggleButton>
                    <TextBlock Name="txtbStatus" Grid.Column="1" Margin="2.5,0,0,0" Text="{Binding AppStatus}" 
                               TextBlock.ToolTip="{Binding AppStatus, StringFormat='Status: {0}'}" />
                </Grid>
            </Grid>
        </StackPanel>

        <Popup Panel.ZIndex="99999" HorizontalAlignment="Right" VerticalAlignment="Bottom" StaysOpen="False"
               IsOpen="{Binding ElementName=tglFullStatus, Path=IsChecked, Mode=TwoWay}">
            <Border BorderBrush="Red">
                <ScrollViewer>
                    <TextBox />
                </ScrollViewer>
            </Border>
        </Popup>
    </Grid>
</Window>